<?php
	header('Content-type: application/json');
	header('Access-Control: allow <*>');
	include("includes/connect.php");
	
	$username = $_GET['username'];
    	$long = $_GET['longitude'];
    	$lat 	= $_GET['latitude'];

		$userCheck 	= mysql_query("SELECT * FROM `user_table` WHERE `username` = '$username'"); 
		$userCheck2	= mysql_fetch_array($userCheck);
		
		if($userCheck2)
		{
			$query = mysql_query("UPDATE `user_table` SET `gps_longitude` = '$long', `gps_latitude` = '$lat' WHERE `username` = '$username'") or die("Cannot connect to database or users table");

    		if($query && $long && $lat)
    		{   
				$resultMSG['message']="Location update succesful.";
				$resultMSG['returnCode']=1;
				echo json_encode($resultMSG);

			}
    		else 
			{
				$resultMSG['message']="Location update failed.";
				$resultMSG['returnCode']=0;
				echo json_encode($resultMSG);
			}
		}
		else
		{
			$resultMSG['message']="User not in table.";
			$resultMSG['returnCode']=0;
			echo json_encode($resultMSG);
		}
?>